﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Webdisk;
using System.Threading;

namespace Webdisk_New
{
	public partial class manage : Form
	{
		public manage()
		{
			InitializeComponent();
		}
		string choose;
		string back = "";//文件后缀名
		int a = 0;

		private void manage_Load(object sender, EventArgs e)
		{
			ColumnHeader ch = new ColumnHeader();
			ch.Text = "路径";
			this.listView1.Columns.Add(ch);
            FileLa.Text = "用户:" + Temp.Name + "的文件";

			DBHelper.Conn.Close();
			SqlDataReader reader = null;
            //MessageBox.Show(Temp.Name);
			reader = DBHelper.GetDataReader(string.Format("select * from Information where loginName='{0}'", Temp.Name));
            //if (reader.Read())
            //    MessageBox.Show("读取成功");
            //else
            //    MessageBox.Show("连接失败");



            while (reader.Read())//listView1存放文件的路径、listViewPic存放图标
			{
				int count = listView1.Items.Count;//获取路径ListView项的总和
				string FilePath = reader["FilePath"].ToString();
				string FileName = reader["FileName"].ToString();
				string FileExt = reader["FileExt"].ToString();
				listView1.Items.Add(FilePath);//将路径加入路径ListView
				if (FileExt.ToLower() == "pptx" || FileExt.ToLower() == "ppt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 12;
				}
				else if (FileExt.ToLower() == "txt")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 9;
				}
				else if (FileExt.ToLower() == "docx" || FileExt.ToLower() == "doc" || FileExt.ToLower() == "rtf" || FileExt.ToLower() == "pdf")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 4;
				}
				else if (FileExt.ToLower() == "xlsx" || FileExt.ToLower() == "xls")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 1;
				}
				else if (FileExt.ToLower() == "exe")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 5;
				}
				else if (FileExt.ToLower() == "torrent")                            //种子文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 14;
				}
				else if (FileExt.ToLower() == "html" || FileExt.ToLower() == "htm")    //网页文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 2;
				}
				else if (FileExt.ToLower() == "dll")                                //dll文件
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 0;
				}
				else if (FileExt.ToLower() == "mp4" || FileExt.ToLower() == "wmv" || FileExt.ToLower() == "rmvb" || FileExt.ToLower() == "3gp" || FileExt.ToLower() == "avi" || FileExt.ToLower() == "mkv" || FileExt.ToLower() == "flv")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 7;
				}
				else if (FileExt.ToLower() == "mp3" || FileExt.ToLower() == "wav" || FileExt.ToLower() == "flac" || FileExt.ToLower() == "ape")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 13;
				}
				else if (FileExt.ToLower() == "zip" || FileExt.ToLower() == "rar" || FileExt.ToLower() == "7z" || FileExt.ToLower() == "iso")
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 15;
				}
				else if (FileExt.ToLower() == "jpg" || FileExt.ToLower() == "bmp" || FileExt.ToLower() == "png" || FileExt.ToLower() == "gif" || FileExt.ToLower() == "jpeg" || FileExt.ToLower() == "ico")
				{
                    //Thread.Sleep(10);
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 8;
				}
				else
				{
					listViewPic.Items.Add(FileName);
					listViewPic.Items[count].ImageIndex = 11;
				}
				//count++;
			}//listView1存放文件的路径、listViewPic存放图标
			reader.Close();
			DBHelper.Conn.Close();
		
		}

		private void listViewPic_DragDrop(object sender, DragEventArgs e)
		{
			string str = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//提取文件路径
			listView1.Items.Add(str);//将路径加入路径ListView
			int count = listView1.Items.Count;//获取路径ListView项的总和
			for (int i = str.Length - 1; i >= 0; i--)
			{
				if (str.Substring(i, 1) == ".")
				{
					//MessageBox.Show("后缀名是：" + str.Substring(i + 1));
					back = str.Substring(i + 1);
					break;
				}
			}
			if (back.ToLower() == "pptx")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 1;
			}
			else if (back.ToLower() == "txt")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 5;
			}
			else if (back.ToLower() == "docx")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 2;
			}
			else if (back.ToLower() == "xlsx")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 0;
			}
			else if (back.ToLower() == "exe")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 3;
			}
			else if (back.ToLower() == "mp4")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 4;
			}
			else if (back.ToLower() == "mp3")
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 3;
			}
			else
			{
				listViewPic.Items.Add(back);
				listViewPic.Items[count - 1].ImageIndex = 6;
			}
		}

		private void listView1_DragEnter(object sender, DragEventArgs e)
		{
			e.Effect = DragDropEffects.Copy;//设置拖放
		}

		private void listViewPic_SelectedIndexChanged(object sender, EventArgs e)
		{

		}

        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            Min.Image = imageList1.Images[16];
        }

        private void pictureBox2_MouseEnter(object sender, EventArgs e)
        {
            Exit.Image = imageList1.Images[17];
        }

        private void pictureBox2_MouseLeave(object sender, EventArgs e)
        {
            Exit.Image = null;
        }

        private void Min_MouseLeave(object sender, EventArgs e)
        {
            Min.Image = null;
        }
        //最小化
        private void Min_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //窗口拖动
        private Point mPoint;
        private void manage_MouseDown(object sender, MouseEventArgs e)
        {
            mPoint = new Point(e.X, e.Y);
        }

        private void manage_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
            }
        }
    }
}
